<?php
require 'inc_security.php';
$ctl_reply = array(1=>'Đã trả lời',2=>'Chưa trả lời');

$list = new dataGrid('ctl_id',30);
$list->add('ctl_title','Tiêu đề','string',1,0);
$list->add('','Ảnh đại diện','string',0,0);

$list->add('','Download','string',1,0);
$list->add('ctl_order','Thứ tụ','string',0,0);

$list->add('ctl_date','Ngày','str',0,1);
$list->add('','Active','',1,0);
$list->add('','Edit','',1,0);
$list->add('','Delete','delete');
//$list->addSearch('Loại sản phẩm','ctl_cat_type','array',$global_product_category_type);
$db_count = new db_count('SELECT count(*) as count 
                            FROM '.$bg_table.'
                            WHERE 1 '.$list->sqlSearch().'
                            ');
$total = $db_count->total;unset($db_count);

$db_listing = new db_query('SELECT * 
                            FROM '.$bg_table.'
                            WHERE 1 '.$list->sqlSearch().'
                            ORDER BY '.$list->sqlSort().' ctl_id DESC
                            '.$list->limit($total));
$total_row = mysql_num_rows($db_listing->result);
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="vi" lang="vi" xmlns:og="http://ogp.me/ns#" xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?=$load_header?>
</head>
<body>
<div class="module_header bold fix"><?=$module_name?></div>
<div id="wrapper">
    <?=$list->showHeader($total_row)?>
    <?php
    $i = 0; 
    ?>
    <?php while($row = mysql_fetch_assoc($db_listing->result)){
        $i++;
    ?>
        <?=$list->start_tr($i,$row[$id_field])?>
        <td>
            <div class="span1"><?=form_input('ctl_title'.$row[$id_field],$row['ctl_title'],'class="span3" onkeyup="check_edit(\'record_'.$i.'\')"')?></div>
        </td>
        <td class="center">
            <div class="img_thumb">
                <img src="<?=$image_filepath?><?=$row[$image_field]?>" alt="Không có ảnh"/>
            </div>
            <?=form_upload($image_field.$row[$id_field],'','onchage="check_edit(\'record_'.$i.'\')"')?>
        </td>
        
        <td>
            <a href="download.php?ctl_id=<?=$row[$id_field]?>"><?=$row['ctl_title']?></a>
            <?=form_upload($ctl_filename.$row[$id_field],'','onchage="check_edit(\'record_'.$i.'\')"')?>
        </td>
        <td>
            <div class="span1"><?=form_input('ctl_order'.$row[$id_field],$row['ctl_order'],'class="span1" onkeyup="check_edit(\'record_'.$i.'\')"')?></div>
        </td>

        <td>
            <?=date('H:m:i - d/m/Y',$row['ctl_date'])?>
        </td>
        <?=$list->showCheckbox('ctl_active',$row['ctl_active'],$row[$id_field])?>
        <?=$list->showEdit($row[$id_field])?>
        <?=$list->showDelete($row[$id_field])?>
        <?=$list->end_tr()?>
    <?}?>
    <?=$list->showFooter()?>
</div>
</body>
</html>